#include <iostream>
#include <vector>
using namespace std;

class segment_tree {
	vector<int> starts;
	vector<int> ends;

	void up(int i)
	{
		starts[i] = starts[i << 1] + starts[i << 1 | 1];
		ends[i] = ends[i << 1] + ends[i << 1 | 1];
	}

    public:
	segment_tree(int n) : starts(n << 2, 0), ends(n << 2, 0)
	{
	}

	void update(int jobt, int jobp, int l, int r, int i)
	{
		if (l == r) {
			if (jobt == 0)
				starts[i]++;
			else
				ends[i]++;
		} else {
			int mid = (l + r) >> 1;
			if (jobp <= mid) {
				update(jobt, jobp, l, mid, i << 1);
			}else{
				update(jobt, jobp, mid + 1, r, i << 1 | 1);
			}
			up(i);
		}
	}

	pair<int, int> query(int jobl, int jobr, int l, int r, int i)
	{
		if (jobl <= r && r <= jobr) {
			return { starts[i], ends[i] };
		}

		int mid = (l + r) >> 1;
		pair<int, int> ans1, ans2;
		if (jobl <= mid) {
			ans1 = query(jobl, jobr, l, mid, i << 1);
		}
		if (mid < jobr) {
			ans2 = query(jobl, jobr, mid + 1, r, i << 1 | 1);
		}
		return { ans1.first + ans2.first, ans1.second + ans2.second };
	}
};

int main()
{
	int n, m;
	cin >> n >> m;
	segment_tree sgt(n);
	pair<int, int> ans1, ans2;
	for (int i = 0, op, l, r; i < m; i++) {
		cin >> op >> l >> r;
		if (op == 1) {
			sgt.update(0, l, 1, n, 1);
                        sgt.update(1, r, 1, n, 1);
		} else {
			ans1 = sgt.query(1, r, 1, n, 1);
			ans2 = sgt.query(1, l - 1, 1, n, 1);
			cout << ans1.first - ans2.second << '\n';
		}
	}
	return 0;
}